home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / lookup.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  7KB  |  295 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9. /* This file has procedures formerly in closerms.c, inprefor.c, clocand.c,
  10.  * errmsgsy.c and tokval.c
  11.  * These procedures in general corresond to various table lookups.
  12.  *    D. Shields    4-2-85
  13.  */
  14.  
  15. /* Automatically Generated */
  16. /* Must be re-generated if */
  17. /* LALR grammar is changed */
  18.  
  19. /*
  20.  *    closer_candidates[opener] := {CLOSER_SYMS(j) | j in CLOSER_MAP_SYMS(opener)}
  21.  *
  22.  *    So, for each opener, there is a list of tuples of closer candidates. Some
  23.  *    may have only one set of these candidates, and the maximum number of tuples
  24.  *    is three. Each set has between 1 and 5 elements.
  25.  *
  26.  *  As and example, for the opener whose symbol is 56, there are two tuples
  27.  *    of closer candidates, viz [80, 21, 80, 37, 10] and [80, 21].
  28.  *
  29.  *    This structure is used by the scope_recovery procedure to generate and
  30.  *    insert possible sequences of closers into the token sequence.
  31.  *
  32.  */
  33.  
  34. #include <string.h>
  35. #include "lookupp.h"
  36.  
  37. char closer_candidates[13][3][5] = {
  38.     {  { 
  39.         80, 21, 80, 37, 10},
  40.         { 80, 21    } 
  41.     },
  42.     {  { 
  43.         80, 33, 21    } 
  44.     },
  45.     {  { 
  46.         80, 21, 80, 37, 10},
  47.         { 80, 21    } 
  48.     },
  49.     {  { 
  50.         80, 21    } 
  51.     },
  52.     {  { 
  53.         72},
  54.         { 80, 72    } 
  55.     },
  56.     {  { 
  57.         38},
  58.         { 65, 38    } 
  59.     },
  60.     {  { 
  61.         80, 12, 21},
  62.         { 31},
  63.         { 61, 31    } 
  64.     },
  65.     {  { 
  66.         80, 48, 21    } 
  67.     },
  68.     {  { 
  69.         80, 29, 21    } 
  70.     },
  71.     {  { 
  72.         80, 53, 21    } 
  73.     },
  74.     {  { 
  75.         80, 29, 21    } 
  76.     },
  77.     {  { 
  78.         80, 21, 80, 37, 10},
  79.         { 80, 21    } 
  80.     },
  81.     {  { 
  82.         80, 29, 21    } 
  83.     },
  84. };
  85.  
  86. /* Automatically Generated */
  87. /* Must be re-generated if */
  88. /* LALR grammar is changed */
  89. /* ERROR_MSG_SYMS */
  90. char   *err_msg_syms (int n)                            /*;err_msg_syms*/
  91. {
  92.     switch (n) {
  93.     case 0:
  94.         return ("Bad compilation");
  95.     case 191:
  96.         return ("Bad component declaration");
  97.     case 256:
  98.         return ("Bad parameter declaration");
  99.     case 99:
  100.         return ("Bad term");
  101.     case 323:
  102.         return ("Bad exception handler");
  103.     case 167:
  104.         return ("Bad discriminant declaration");
  105.     case 298:
  106.         return ("Bad exception choice");
  107.     case 171:
  108.         return ("Bad choice");
  109.     case 108:
  110.         return ("Bad compilation");
  111.     case 268:
  112.         return ("Bad entry declaration");
  113.     case 173:
  114.         return ("Bad declaration");
  115.     case 204:
  116.         return ("Bad factor");
  117.     case 238:
  118.         return ("Bad condition in if statement");
  119.     case 301:
  120.         return ("Bad generic formal");
  121.     case 242:
  122.         return ("Bad case alternative");
  123.     case 278:
  124.         return ("Bad select alternative");
  125.     case 217:
  126.         return ("Bad statement");
  127.     case 156:
  128.         return ("Bad index specification");
  129.     default :
  130.         return("") ;
  131.     }
  132. }
  133. int in_beacon(int n)                                        /*;in_beacon*/
  134. {
  135.     /* macro in_BEACON_SYMS, formerly in recover.h,is now a procedure
  136.  * this simplifies files for PC and avoids problems with -cram option
  137.  * of HIC when run with reduced memory
  138.  *    ds    30-mar-85
  139.  */
  140.     /* BEACON_SYMS */
  141.     /* the procedure is now in_beacon*/
  142.     return
  143.         ((n == 10) || (n == 18) || (n == 19) || (n == 20) || (n == 21)
  144.         || (n == 25) || (n == 26) || (n == 29) || (n == 31) || (n == 33)
  145.         || (n == 42) || (n == 45) || (n == 51) || (n == 56) || (n == 58)
  146.         || (n == 62) || (n == 80)) ;
  147. }
  148.  
  149. /*            PREFERRED_FOR_SYMS                */
  150.  
  151. /*
  152.  * returns true if u is in the set of PREFERRED_FOR_SYMS of v
  153.  *
  154.  */
  155. int in_PREFERRED_FOR_SYMS (int u, int v)        /*;in_PREFERRED_FOR_SYMS*/
  156. {
  157.     switch(u)    {
  158.     case 66 : 
  159.         return(v == 65) ;
  160.     case 65 : 
  161.         return(v == 45) ;
  162.     case 38 : 
  163.         return(v == 31) ;
  164.     case 77 : 
  165.         return(v == 86) ;
  166.     case 82 : 
  167.         return(v == 88) ;
  168.     case 80 : 
  169.         return(v == 33) ;
  170.     case 18 : 
  171.         return(v == 33) ;
  172.     case 25 : 
  173.         return(v == 33) ;
  174.     case 88 : 
  175.         return((v == 82) || (v == 31)) ;
  176.     case 55 : 
  177.         return(v == 59) ;
  178.     case 31 : 
  179.         return((v == 38) || (v == 88)) ;
  180.     case 59 : 
  181.         return(v == 55) ;
  182.     default : 
  183.         return(0) ;
  184.     }
  185. } /* End PREFERRED_FOR_SYMS */
  186.  
  187. int is_opener(int t)                                        /*;is_opener*/
  188. /* The macro in_OPENER_SYMS, formerly in recover.h,
  189.  * is now part of this procedure.
  190.  *        ds 3-30-85
  191.  */
  192. {
  193.     return
  194.         (((t)==8)
  195.         || ((t)==10)
  196.         || ((t)==12)
  197.         || ((t)==19)
  198.         || ((t)==20)
  199.         || ((t)==29)
  200.         || ((t)==33)
  201.         || ((t)==42)
  202.         || ((t)==48)
  203.         || ((t)==53)
  204.         || ((t)==56)
  205.         || ((t)==71)
  206.         || ((t)==251)
  207.         );
  208. }
  209.  
  210. int    open_index (int n)                                    /*;open_index*/
  211. /*
  212.  *    This function maps the value of an opener to a number in the
  213.  *  range 0 to 12 for use as an array index.
  214.  */
  215. {
  216.     switch (n) {
  217.     case 251:
  218.         return (0);
  219.     case 33:
  220.         return (1);
  221.     case 42:
  222.         return (2);
  223.     case 10:
  224.         return (3);
  225.     case 71:
  226.         return (4);
  227.     case 8:
  228.         return (5);
  229.     case 12:
  230.         return (6);
  231.     case 48:
  232.         return (7);
  233.     case 19:
  234.         return (8);
  235.     case 53:
  236.         return (9);
  237.     case 20:
  238.         return (10);
  239.     case 56:
  240.         return (11);
  241.     case 29:
  242.         return (12);
  243.     }                /* case */
  244.     return (0); /* shouldn't reach here, this for lint's sake */
  245. }
  246.  
  247. char * token_val_des(char *t)                             /*;token_val_des*/
  248. {
  249.     if (!strcmp("identifier",t) )
  250.         return ("any_id")  ;
  251.     if (!strcmp("numeric_literal",t) )
  252.         return ("0")  ;
  253.     if (!strcmp("character_literal", t))
  254.         return ("'?'")    ;
  255.     if (!strcmp("string_literal", t) )
  256.         return ("") ;
  257.     return (t) ;
  258. }
  259. /* CLOSER_MESSAGE_SYMS */
  260. char   *CLOSER_MESSAGE_SYMS (int n)            /*;CLOSER_MESSAGE_SYMS*/
  261. {
  262.     /* The value of n is an encoding of the tuple */
  263.     /* generated merely by adding their values */
  264.     switch (n) {
  265.     case 38 /* [ 38 ] */ :
  266.         return ("\"OF\" inserted to match \"ARRAY\"");
  267.     case 152 /* [ 80 72 ] */ :
  268.         return ("\");\" inserted to match \"(\"");
  269.     case 72 /* [ 72 ] */ :
  270.         return ("\")\" inserted to match \"(\"");
  271.     case 113 /* [ 80 12 21 ] */ :
  272.         return (" \"END CASE;\" inserted to match \"CASE\"");
  273.     case 103 /* [ 65 38 ] */ :
  274.         return ("\"OF IDENTIFIER\" inserted to match \"ARRAY\"");
  275.     case 130 /* [ 80 29 21 ] */ :
  276.         return (" \"END IF;\" inserted to match \"IF\"");
  277.     case 149 /* [ 80 48 21 ] */ :
  278.         return (" \"END RECORD;\" inserted to match \"RECORD\"");
  279.     case 134 /* [ 80 33 21 ] */ :
  280.         return (" \"END LOOP;\" inserted to match \"LOOP\"");
  281.     case 228 /* [ 80 21 80 37 10 ] */ :
  282.         return ("statement part missing for unit starting");
  283.     case 154 /* [ 80 53 21 ] */ :
  284.         return (" \"END SELECT;\" inserted to match \"SELECT\"");
  285.     case 31 /* [ 31 ] */ :
  286.         return ("\"IS\" inserted to match \"CASE\"");
  287.     case 92 /* [ 61 31 ] */ :
  288.         return ("\"IS WHEN\" inserted to match \"CASE\"");
  289.     case 101 /* [ 80 21 ] */ :
  290.         return ("\"END;\" inserted to match current scope opened");
  291.     }
  292.     /* shouldn't reach here give string for sake of lint */
  293.     return("");
  294. }                /* CLOSER_MESSAGE_SYMS */
  295.